home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
more13.zip
/
MORE.C
< prev
next >
Wrap
Text File
|
1990-06-26
|
30KB
|
1,416 lines
/* Special More */
#ifndef __COMPACT__
#error Use COMPACT memory model
#endif
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <alloc.h>
#include <assert.h>
#include <conio.h>
#include <string.h>
#include <process.h>
#include <dir.h>
#define MAXLINES 32000
#define MAXLEN 2048
#define CASE_SEN 1
#define NORMAL 2
#define REPEAT 3
#define REVERSE 4
#define GET 0
#define SET 1
#define WRITE_FILE 0
#define WRITE_BLOCK 1
#define highlight() { textcolor(col[2]);textbackground(col[5]); }
#define inverse() { textcolor(col[1]);textbackground(col[4]); }
#define normal() { textcolor(col[0]);textbackground(col[3]); }
#define flashing() { textcolor(col[2] + BLINK);textbackground(col[5]); }
#define rest_keys() gotoxy(1,25);inverse();cprintf(keys);clreol();normal()
#define rest_message() gotoxy(1,1);inverse();cprintf(message);clreol();normal()
#define open_con_w() freopen("con","wt",stdout); setbuf(stdout, NULL)
#define ESC 27
#define UPARROW 72+256
#define DOWNARROW 80+256
#define LEFTARROW 75+256
#define RIGHTARROW 77+256
#define HOME 71+256
#define END 79+256
#define PGUP 73+256
#define PGDN 81+256
#define CTRLPGUP 132+256
#define CTRLPGDN 118+256
#define CTRLRIGHT 115+256
#define F1 59+256
#define F7 65+256
#define F8 66+256
#define F9 67+256
#define F10 68+256
void read_file(void);
void display(void);
void putseg(int loc, int line, int start);
void disp_page(int column, int line);
void open_kbd(void);
void open_file(void);
int open_prn(void);
int getscan(void);
char *_cgets(char *s);
char getline(char *s);
void strseg(char *dest, char *src, int start, int len);
int find(int type, int line);
void help(int line, int column);
void print(int line, int column);
void print_all(void);
void colors(int column, int line);
void printer(int column, int line);
void editor(int column, int line);
void read_setup(void);
void write_setup(void);
int bookmark(int cmd, int line);
int goto_line(int line);
void read_name(void);
void write_file(int func);
void edit(void);
int tot_lines;
char filename[129];
char prg_path[129];
char message_str[66];
char file_r;
int block_begin = -32767;
int block_end = -32767;
struct str_struct *ptrs[(MAXLINES/32)+1];
int col[6] = { LIGHTGRAY, BLACK, WHITE, BLACK, LIGHTGRAY, BLACK };
#define NOSTOR "%s: insufficent memory for file"
#define FNDERR "%s: structure managament error"
int cr = 0;
#define chkptr(x) if( x == NULL ) { clrscr(); printf(NOSTOR,name); exit(2); }
#define chkfail() if( find_fail ) { clrscr(); printf(FNDERR,name); exit(2); }
#define str_size sizeof(struct str_struct)
struct str_struct {
int rec_num;
long pos;
char *str[32];
};
char *ptr(int line);
void setptr(int line, char *s);
int bookmarks[10] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
char port[68] = "prn";
char edit_cmd[68] = "edit @";
char prg_name[128];
char name[9];
char *keys = "Keys: cursor, Find Case Next Back, Print All, block: +-*, Get Set, Line F1=Help";
char *message = "Enhanced More by Daniel Sachs. Copyright 1990 by Daniel Sachs.";
char *date = __DATE__;
void main(int argc, char *argv[])
{
argc--;
open_con_w();
strcpy(prg_name,argv[0]);
read_name();
if (argv[0] == NULL)
{
printf("%s: DOS 3.0 or greater required",name);
exit(2);
}
if (argc > 1)
{
printf("%s: too many arguments. syntax: %s <filename>\n\r",name,name);
printf("%s: if no file is specified, reads standard input",name);
exit(2);
}
if (argc == 1)
{
file_r = 1;
strcpy(filename,argv[1]);
open_file();
if (strlen(filename) < 65)
{
strcpy(message_str,filename);
message = strupr(message_str);
}
else
{
int i,j;
strcpy(message_str,"\x11\xc4\xc4");
j = strlen(filename)-56;
for(i=0;i<60;i++)
message_str[i+3]=*(filename+j+i);
message_str[i] = 0;
message = strupr(message_str);
}
}
else
file_r = 0;
directvideo = 1;
read_setup();
normal();
clrscr();
highlight();
gotoxy(1,24);
if (!file_r)
cputs("Reading standard input, please wait...");
else
cputs("Reading file, please wait...");
gotoxy(23,5);
cputs("E N H A N C E D M O R E v1.3\n\n\n\r");
normal();
cputs("written 6/90 by Daniel Sachs, copyright 1990 by Daniel Sachs\n\r");
cputs("written in Turbo C. Portions copyright 1988 by Borland, Inc.");
cprintf("\r\n\nCompiled on %s.",date);
read_file();
display();
window(1,1,80,25);
gotoxy(1,25);
clreol();
exit(0);
}
void read_name(void)
{
char fdrive[3];
char fdir[65];
char fext[5];
fnsplit(prg_name,fdrive,fdir,name,fext);
strlwr(name);
}
void read_file(void)
{
char s[MAXLEN],eof,*tmp;
int i,j;
gotoxy(1,20);
for (i=0;;i++)
{
if (i == MAXLINES)
{
clrscr();
printf("%s: file is too long",name);
exit(2);
}
eof = getline(s);
tmp = malloc(strlen(s)+1);
if (tmp == NULL)
{
clrscr();
printf("%s: insufficient memory for file",name);
exit(2);
}
strcpy(tmp,s);
setptr(i,tmp);
if ((i % 40) == 0)
{
gotoxy(50,24);
cprintf("Line %5i. %3iK Free.",i,(int)(coreleft()/1024));
gotoxy(1,20);
}
if (eof)
{
for(j=0;j<strlen(s);j++)
if(s[j] != 32)
{
i++;
break;
}
break;
}
}
tot_lines = i-1;
for (;i < tot_lines+24;i++)
setptr(i,"");
}
void read_setup(void)
{
FILE *setup;
char fdrive[3];
char fdir[65];
char fnam[9];
char fext[5];
char name[127];
fnsplit(prg_name, fdrive, fdir, fnam, fext);
strcpy(fext,".CFG");
fnmerge(name, fdrive, fdir, fnam, fext);
setup = fopen(name,"rt");
if (setup != NULL)
{
fread(edit_cmd, 1, 68, setup);
fread(port, 1, 68, setup);
fread(col, 2, 6, setup);
fclose(setup);
}
}
void write_setup(void)
{
FILE *setup;
char fdrive[3];
char fdir[66];
char fnam[10];
char fext[5];
char path[127];
fnsplit(prg_name, fdrive, fdir, fnam, fext);
strcpy(fext,".CFG");
fnmerge(path, fdrive, fdir, fnam, fext);
setup = fopen(path,"wb");
if (setup != NULL)
{
fwrite(edit_cmd, 1, 68, setup);
fwrite(port, 1, 68, setup);
fwrite(col, 2, 6, setup);
fclose(setup);
}
else
putchar(7);
}
void open_kbd(void)
{
freopen("con","rt",stdin);
assert(stdin != NULL);
}
void open_file(void)
{
FILE *filetest;
filetest=freopen(filename,"rt",stdin);
if (filetest == NULL)
{
printf("%s: unable to open file",name);
exit(4);
}
}
int open_prn(void)
{
FILE *filetest;
filetest=freopen(port,"wt",stdprn);
return(filetest != NULL);
}
char getline(char *s)
{
int i,j,x,eof,col;
char t[MAXLEN];
static char message = 0;
for(i=0;;i++)
{
x = getchar();
eof = x == EOF;
if (((x != EOF) && (x != '\n')) && (i < MAXLEN-1))
t[i]=(char)x;
else
break;
}
t[i]=0;
if ((i>=MAXLEN-1) && !message)
{
gotoxy(1,23);
cprintf("%s: lines too long, split...",name);
message=1;
gotoxy(1,20);
}
x = 0;
col = 1;
for (i=0;i<strlen(t);i++)
{
if (t[i]!='\t')
{
s[x++]=t[i];
col++;
}
els